const url = "mongodb://chat:sxtang1377@localhost:27017/chatroom";
const mongoose = require("mongoose");

mongoose.Promise = global.Promise;
const connection = mongoose.connection;

mongoose.connect(
    url,
    {
        authdb: "chatroom",
        useNewUrlParser: true
    }
);

connection.on("connected", () => {
    console.log("MongoDB WeChat has been conntected!");
});

connection.on("error", err => {
    console.log("MongoDB has a error:" + err);
});

connection.on("disconnected", () => {
    console.log("Mongoose connection disconnected");
});

module.exports = mongoose;
